package com.zbkj.admin.controller.merchant.v2;

import com.zbkj.admin.model.req.UnbindMerchantReq;
import com.zbkj.admin.model.req.UpdateBindMerchantReq;
import com.zbkj.admin.model.req.UserOperateQuotaReq;
import com.zbkj.admin.model.vo.CalculateAfterBalanceVO;
import com.zbkj.admin.service.AdminFundV2Service;
import com.zbkj.admin.service.AdminUserV2Service;
import com.zbkj.dal.base.result.CommonResult;
import com.zbkj.dal.pojo.request.UserOperateBalanceRequest;
import com.zbkj.dal.pojo.request.UserUpdateSpreadRequest;
import com.zbkj.service.model.front.req.user.UpdateUserIdentityReq;
import com.zbkj.service.model.front.req.user.UserLogoffReq;
import com.zbkj.service.model.front.req.user.UserUpdateAuthorityReq;
import com.zbkj.service.service.RetailStoreService;
import com.zbkj.service.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(value = "管理后台用户管理")
@RestController
@RequestMapping("/api/admin/merchant/v2/user")
public class MerchantUserV2Controller {

    @Resource
    private RetailStoreService retailStoreService;

    @Resource
    private AdminUserV2Service adminUserV2Service;

    @Resource
    private AdminFundV2Service adminFundV2Service;

    @ApiOperation("修改用户身份")
    @PostMapping("/update/identity")
    public CommonResult<Void> updateUserIdentity(@RequestBody @Validated UpdateUserIdentityReq req) {
        adminUserV2Service.updateUserIdentity(req);
        return CommonResult.success();
    }

    @ApiOperation("修改用户分润权限")
    @PostMapping("/update/share-profit")
    public CommonResult<Void> updateShareProfit(@RequestBody @Validated UserUpdateAuthorityReq req) {
        adminUserV2Service.updateShareProfit(req);
        return CommonResult.success();
    }


    @ApiOperation("用户拉黑/取消拉黑")
    @PostMapping("/operate/blacklist")
    public CommonResult<Void> userBlacklist(@RequestBody @Validated UserUpdateAuthorityReq req) {
        adminUserV2Service.userBlacklist(req);
        return CommonResult.success();
    }

    @ApiOperation(value = "用户注销")
    @PostMapping(value = "/logoff")
    public CommonResult<Void> logoff(@RequestBody @Validated UserLogoffReq req) {
        adminUserV2Service.logoff(req);
        return CommonResult.success();
    }


    @ApiOperation(value = "解绑店铺")
    @PostMapping(value = "/unbind/merchant")
    public CommonResult<Void> unbindMerchant(@RequestBody @Validated UnbindMerchantReq req) {
        adminUserV2Service.unbindMerchant(req);
        return CommonResult.success();
    }

    @ApiOperation(value = "换绑店铺")
    @PostMapping(value = "/update/bind/merchant")
    public CommonResult<Void> updateBindMerchant(@RequestBody @Validated UpdateBindMerchantReq req) {
        adminUserV2Service.updateBindMerchant(req);
        return CommonResult.success();
    }

    @ApiOperation(value = "操作用户额度")
    @PostMapping(value = "/operate/quota")
    public CommonResult<Void> operateQuota(@RequestBody @Validated UserOperateQuotaReq request) {
        if (adminFundV2Service.operateQuota(request)) {
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

    @ApiOperation(value = "计算操作后等级计算额度")
    @RequestMapping(value = "/calculate/after/quota", method = RequestMethod.GET)
    public CommonResult<CalculateAfterBalanceVO> calculateAfterQuota(@Validated UserOperateQuotaReq request) {
        return CommonResult.success(adminFundV2Service.calculateAfterQuota(request));
    }
    @ApiOperation(value = "修改用户上级推广人")
    @RequestMapping(value = "/update/user/spread", method = RequestMethod.POST)
    public CommonResult<String> updateUserSpread(@Validated @RequestBody UserUpdateSpreadRequest request) {
        if (retailStoreService.updateUserSpread(request)) {
            return CommonResult.success("修改成功");
        }
        return CommonResult.failed("修改失败");
    }
}
